<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <!--<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>-->
    <!--<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>-->
    <!--[endif]-->
    <script type="text/javascript" src="../../common/js/public.js"></script>
    <script type="text/javascript" src="../../common/js/publicUtils.js"></script>
    <style>
        .layui-input-inline,.buttondiv .layui-input-inline {
            float: left;
            width: 450px !important;
            margin-right: 10px;
        }
        .error{
            color: red;
            line-height: 20px;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form"  id="changepassform" lay-filter="changepassform">
            <input type="hidden" name="id">
            <div class="layui-form-item">
                <label class="layui-form-label" for="loginName">用&ensp;户&ensp;名</label>
                <div class="layui-input-inline">
                    <input type="text" name="loginName" id="loginName" lay-verify="title" autocomplete="off" placeholder="请输入菜单名称" class="layui-input" readonly>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="password">原&ensp;密&ensp;码</label>
                <div class="layui-input-inline">
                    <input type="text" name="password" id="password" autocomplete="off" class="layui-input pname" >
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" for="newpassword">新&ensp;密&ensp;码</label>
                    <div class="layui-input-inline">
                        <input type="text" name="newpassword" id="newpassword" autocomplete="off" class="layui-input" >
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" for="rnewpassword">确认密码</label>
                    <div class="layui-input-inline">
                        <input type="text" name="rnewpassword" id="rnewpassword" autocomplete="off" class="layui-input" >
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    var loginName,loginId;
    $(function () {

    })

    function initData(name,id){
        $("#loginName").val(name);
        loginName = name;
        loginId = id;
    }

    function updatePerson(){
        var obj = $(validform().form());
        if(!obj[0]){
            return false;
        }
        var data = {'id':loginId,'password':hex_md5($("#newpassword").val()),'flag':2};
        var result;
        publicAjax (null,'login/changePassWord',data,false,null,function (r) {
            if(r.code==2000){
                laysuccess("修改成功",null);
                result = r;
            }else{
                layerror("修改失败",null);
                result = r;
            }
        })
        return result;
    }

    //编写表单验证函数validform，在验证按钮注册按钮点击事件内调用验证函数对象
    function validform(){
        /*关键在此增加了一个return，返回的是一个validate对象，这个对象有一个form方法，返回的是是否通过验证*/
        jQuery.validator.addMethod("newpassword",function(value,element,param){
            var data;
            var changepassurl = "login/changePassWord"
            data = {"loginName":$("#loginName").val(),"password":hex_md5(value),'flag':1};
            var obj = true;
            publicAjax (null,changepassurl,data,false,null,function (r) {
                if(r.code==2000){
                    if(r.data>0){
                        obj = true;
                    }else{
                        obj = false;
                    }
                }else{
                    obj = false;
                }
            })
            return obj;
        },"原密码不正确！");
        jQuery.validator.addMethod("rnewpassword",function(value,element,param){
            var changepassurl = "login/changePassWord";
            var newpassword = $("#newpassword").val();
            if(newpassword===value){
                return true;
            }else{
                return false;
            }
        },"两次密码不一致！");
        return $("#changepassform").validate({
            rules : {
                password:{
                    required:true,
                    newpassword: true,
                    normalizer: function( value ) {
                        return $.trim( value );
                    }
                },
                newpassword : {
                    required:true,
                    normalizer: function( value ) {
                        return $.trim( value );
                    }
                },
                rnewpassword: {
                    required: true,
                    rnewpassword: true,
                    normalizer: function (value) {
                        return $.trim(value);
                    }
                }
            },
            messages : {
                password: {
                    required: "原密码不能为空"
                },
                newpassword: {
                    required: "新密码不能为空"
                },
                rnewpassword: {
                    required: "新密码不能为空"
                }
            }
        });
    }


    </script>
</body>

</html>
